package com.honyelchak.shortlink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.honyelchak.shortlink.admin.remote.ShortLinkRemoteService;
import com.honyelchak.shortlink.admin.remote.req.ShortLinkCreateReqDTO;
import com.honyelchak.shortlink.admin.remote.req.ShortLinkPageReqDTO;
import com.honyelchak.shortlink.admin.remote.req.ShortLinkUpdateReqDTO;
import com.honyelchak.shortlink.admin.remote.resp.ShortLinkCreateRespDTO;
import com.honyelchak.shortlink.admin.remote.resp.ShortLinkPageRespDTO;
import com.honyelchak.shortlink.base.common.convention.result.Result;
import com.honyelchak.shortlink.base.common.convention.result.Results;
import org.springframework.web.bind.annotation.*;

/**
 * 短链接远程调用控制层
 *
 * @author Honyelchak
 */
@RestController
public class ShortLinkController {

    private final ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService() {
    };


    /**
     * 创建短链接
     */
    @PostMapping("/api/short-link/admin/v1/link/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO repDTO) {
        return shortLinkRemoteService.createShortLink(repDTO);
    }


    /**
     * 分页查询短链接
     */
    @GetMapping("/api/short-link/admin/v1/link/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO repDTO) {
        return shortLinkRemoteService.pageShortLink(repDTO);
    }

    /**
     * 更新短链接
     */
    @PutMapping("/api/short-link/v1/update")
    public Result<Void> createShortLink(@RequestBody ShortLinkUpdateReqDTO reqDTO) {
        shortLinkRemoteService.updateShortLink(reqDTO);
        return Results.success();
    }

//    @GetMapping("/api/short-link/admin/v1/link/count")
//    public Result<List<ShortLinkCountQueryRespDTO>> listGroupShortLinkCount(List<String> gids) {
//        return shortLinkRemoteService.listGroupShortLinkCount(gids);
//    }

}
